package com.dem.android.adapter;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.dem.android.R;
import com.dem.android.db.DemQuery;
import com.dem.android.imLoader.ImageLoaderNew;

public class DemRuAdapter extends CursorAdapter {
	private LayoutInflater mInflater;
	private ImageLoaderNew imLoader;

	public DemRuAdapter(Context context, Cursor c) {
		super(context, c, false);
		imLoader = new ImageLoaderNew(context);
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	@Override
	public void bindView(View view, Context context, Cursor arg2) {
		final YTubeViewHolder listItem = (YTubeViewHolder) view.getTag();
		final String thumbnail = getCursor().getString(DemQuery.THUMBNAIL);
		listItem.image.setTag(thumbnail);
		imLoader.displayImage(thumbnail, (Activity) context, listItem.image);
	}

	@Override
	public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View view = mInflater.inflate(R.layout.list_item_demru, null);
		final YTubeViewHolder listItem = new YTubeViewHolder();
		listItem.image = (ImageView) view.findViewById(R.id.image);
		view.setTag(listItem);
		return view;
	}

	public class YTubeViewHolder {
		ImageView image;

	}
}
